import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'url'
import compression from 'vite-plugin-compression'
export default defineConfig({
  plugins: [
    vue(),
    compression({
      ext: '.gz',
      threshold: 10240 // 文件大小超过此阈值（默认为10kb）时才进行gzip压缩
    }),
    // ...
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia']
    }),
    Components({})
  ],
  base: './',
  build: {
    chunkSizeWarningLimit: 1000,
    sourcemap: false,
    rollupOptions: {
      manualChunks(id) {
        if (id.includes('node_modules')) {
          return id.toString().split('node_modules/')[1].split('/')[0].toString()
        }
      }
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      },
      format: {
        comments: false
      }
    }
  },
  server: {
    port: 5173,
    host: '0.0.0.0',
    // proxy: {
    //   '/api': {
    //     target: 'http://192.168.31.200:8840',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, '/api/v1')
    //   }
      
    // }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '~': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
